package Thread;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.ParseException;
import org.apache.http.message.BasicNameValuePair;
import org.apache.log4j.Logger;

import DAO.GoodsDao;
import Utils.Http;

public class RequestNotifyThread implements Runnable {
	static Logger logger = Logger.getLogger(RequestNotifyThread.class);

	@Override
	public void run() {
		try {
			// StringUtils.isNotBlank(getCode)
			List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
			if (sign != null) {
				nameValuePairs.add(new BasicNameValuePair("sign", sign));
			}
			if (timestamp != null) {
				nameValuePairs.add(new BasicNameValuePair("timestamp",
						timestamp));
			}
			if (status != null) {
				nameValuePairs.add(new BasicNameValuePair("boxStatus", status));
			}
			if (orderStatus != null) {
				nameValuePairs.add(new BasicNameValuePair("orderStatus",
						orderStatus));
			}
			if (saveOpenCode != null) {
				nameValuePairs.add(new BasicNameValuePair("saveOpenCode",
						saveOpenCode));
			}
			if (getOpenCode != null) {
				nameValuePairs.add(new BasicNameValuePair("getOpenCode",
						getOpenCode));
			}
			if (orderNum != null) {
				nameValuePairs.add(new BasicNameValuePair("orderNo", orderNum));
			}
			if (funcName != null) {
				nameValuePairs
						.add(new BasicNameValuePair("funcName", funcName));
			}
			if (boxNum != null) {
				nameValuePairs.add(new BasicNameValuePair("boxNum", boxNum));
			}
			if (cancelTime != null) {
				nameValuePairs.add(new BasicNameValuePair("cancelTime",
						cancelTime));
			}
			String responseString = null;
			// if (flag != null&&"forceOpen".equals(flag)) {
			// Goods goods = null;
			// for(int i=0;i<5;i++){
			// Thread.sleep(60000);
			// goods = goodsDao.getGoodsByOrderNo(orderNum);
			// if("0".equals(goods.getIsForcedOpen())){break;}
			// }
			// if("1".equals(goods.getIsForcedOpen())){
			// goodsDao.updateForcedOpenByOrderNo(orderNum, "0");
			// nameValuePairs.add(new BasicNameValuePair("boxStatus", "8"));
			// responseString = Http.postByPair(url, nameValuePairs);
			// }
			// }else{
			logger.info(nameValuePairs);
//			System.out.println("反馈信息--------"+nameValuePairs);
			responseString = Http.postByPair(url, nameValuePairs);
			// }
//			System.out.println("返回结果--------"+responseString);
			// JSONObject responseJSON;
			// for(int i=1;i<=3;i++){
			// responseJSON = JSONObject.fromObject(responseString);
			// }
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	// http://118.244.139.81:8080/erp/feedback
	private String sign = null;
	private String timestamp = null;
	private String funcName = null;
	private String orderNum = null;
	private String status = null;
	private String orderStatus = null;
	private String saveOpenCode = null;
	private String getOpenCode = null;
	private String boxNum = null;
	private String url = null;
	private String cancelTime = null;

	GoodsDao goodsDao = new GoodsDao();

	public String getFuncName() {
		return funcName;
	}

	public String getSign() {
		return sign;
	}

	public String getTimestamp() {
		return timestamp;
	}

	public void setFuncName(String funcName) {
		this.funcName = funcName;
	}

	public void setSign(String sign) {
		this.sign = sign;
	}

	public void setTimestamp(String timestamp) {
		this.timestamp = timestamp;
	}

	public String getUrl() {
		return url;
	}

	public String getOrderNum() {
		return orderNum;
	}

	public String getStatus() {
		return status;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public void setOrderNum(String orderNum) {
		this.orderNum = orderNum;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public String getBoxNum() {
		return boxNum;
	}

	public void setBoxNum(String boxNum) {
		this.boxNum = boxNum;
	}

	public String getCancelTime() {
		return cancelTime;
	}

	public void setCancelTime(String cancelTime) {
		this.cancelTime = cancelTime;
	}

	public String getSaveOpenCode() {
		return saveOpenCode;
	}

	public void setSaveOpenCode(String saveOpenCode) {
		this.saveOpenCode = saveOpenCode;
	}

	public String getGetOpenCode() {
		return getOpenCode;
	}

	public void setGetOpenCode(String getOpenCode) {
		this.getOpenCode = getOpenCode;
	}

	public String getOrderStatus() {
		return orderStatus;
	}

	public void setOrderStatus(String orderStatus) {
		this.orderStatus = orderStatus;
	}

}
